package org.example.rzfx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.rzfx.entity.Log;
import java.util.List;
import java.util.Map;

/**
 * 日志Mapper
 */
@Mapper
public interface LogMapper extends BaseMapper<Log> {
    
    /**
     * 统计日志级别分布
     */
    @Select("SELECT log_level as logLevel, COUNT(*) as count FROM log " +
            "WHERE timestamp >= #{startTime} AND timestamp <= #{endTime} " +
            "GROUP BY log_level")
    List<Map<String, Object>> statLogLevelDistribution(@Param("startTime") String startTime, 
                                                        @Param("endTime") String endTime);
    
    /**
     * 统计系统类型分布
     */
    @Select("SELECT system_type as systemType, COUNT(*) as count FROM log " +
            "WHERE timestamp >= #{startTime} AND timestamp <= #{endTime} " +
            "GROUP BY system_type")
    List<Map<String, Object>> statSystemDistribution(@Param("startTime") String startTime, 
                                                      @Param("endTime") String endTime);
    
    /**
     * 统计日志量趋势（按小时）
     */
    @Select("SELECT DATE_FORMAT(timestamp, '%Y-%m-%d %H:00:00') as time, COUNT(*) as count " +
            "FROM log WHERE timestamp >= #{startTime} AND timestamp <= #{endTime} " +
            "GROUP BY DATE_FORMAT(timestamp, '%Y-%m-%d %H:00:00') ORDER BY time")
    List<Map<String, Object>> statLogTrend(@Param("startTime") String startTime, 
                                            @Param("endTime") String endTime);
}

